Ajax. BeginForm: submits forms asynchronously and updates data. ajax. beginform forms
Using (Ajax. BeginForm ("GetBasicInformation", "Employee ",//New AjaxOptions {UpdateTargetId = "basicInfo", // sets the ID of the HTML element.
Asp.net mvc Ajax. BeginForm cannot be refreshed asynchronously, or switched to a new page, or the page is refreshed.
I made an afternoon of Ajax yesterday. beginForm failed to Implement Asynchronous refresh, and the returned data was always submitted to a new page. I searched for n methods on the Internet, but I asked
HTML. beginform and Ajax. beginform is a form Element in the MVC Architecture. They can be seen literally, namely, HTML. beginform is a normal form submission, while Ajax. beginform supports asynchronous form submission, which is
using (Ajax.beginform ("Getbasicinformation", "Employee",//New Ajaxoptions {Updatetargetid = "basicinfo",//sets the ID of the HTML element, and the content received from the server is inserted into the elementLoadingelementid= "Loading",//Specifies the ID of the HTML element, which is the HTML element to be displayed during the execution of the AJAX requestLoadingelementduration = 3000,//Specifies the duration of the animation for exposing the element
The running result is to generate a form.
Generally, form submission involves a strong type, so we usually need @ model MvcApp. controllers. userInfo command. Let's see if you use @ using (Html. beginForm () and Html. beginForm ();, Html. endForm.
We can find that BeginForm returns an MvcForm, while MvcForm must be as follows: public class MvcForm: IDisposable
I
To display the drop-down list on the page, you can directly use the
In ASP. net mvc, you can use @ html. dropdownlist to create a drop-down list.
Data preparation in controller is as follows:
// Obtain the region information list
In the controller, a list
On the front-end cshtml pageCodeAs follows:
VaR deptselectitems = (list
As follows:
Html. beginform is also relatively simple to use. Just write the following code in cshtm
= m.shipinfo.deliverprovince)@Html. hiddenfor (M = m.shipinfo.delivercity)@Html. hiddenfor (M = m.shipinfo.delivercityarea)}1. The HTML tag name is the same as the parameter namePublic ActionResult Shipping (string shipinfo.delivertype,string shipinfo.delivercountry,string Shipinfo.deliverprovince,string shipinfo.delivercity,string shipinfo.delivercityarea) {}2.HTML Label the Name property is consistent with the model propertyPublic ActionResult Shipping (Models.ViewModels.Order.OrderViewModel
Analysis on the use of Ajax in Asp.net MVC and mvcajax
1. Use System. Web. Mvc. Ajax
1.1 System. Web. Mvc. Ajax. BeginForm
1.2 System. Web. Mvc. Ajax. ActionLink
2. manually create your own "non-invasive" Javascript"
1. Use System. Web. Mvc.
This article mainly describes the use of Ajax summary, and AJAX configuration, call, Chinese garbled, form submission, and so on in detail, now let's look at this article
use of jquery0. You must first introduce jquery.js or you cannot invoke the jquery framework1, JS case-sensitive, from the name of the time to pay attention to2. jquery Gets the value of the page text based on the ID property of P: $ ("#de
There are many ways to implement Ajax in MVC. Microsoft's microsoftajax can also be implemented using jquery's Ajax. If you are familiar with other JavaScript frameworks, you can also use other implementation schemes, such as prototype.
The following are Microsoft's own implementation solutions.
JavaScript files to be preloaded:
Script SRC =" @ URL. Content ( "~ /Scripts/microsoftajax. js"
There are many ways to implement Ajax in MVC. Microsoft's microsoftajax can also be implemented using jquery's Ajax. If you are familiar with other JavaScript frameworks, you can also use other implementation schemes, such as prototype.
The following are Microsoft's own implementation solutions.
JavaScript files to be preloaded:
Script SRC =" @ URL. Content ( "~ /Scripts/microsoftajax. js"
(); myJsonResult = newsCollection; return myJsonResult; }
Method 2: Ajax call using Jquery:
In VS 2010, IDE fully supports the intelligent display of Jquery. In development, Jq is used to achieve excellent JS effects, saving a lot of energy and time. Therefore, using JQuery for development in Ajax is also a good method.
The approximate implementation code is
Examples of Ajax and $. ajax usage (recommended), ajax. ajax
Instance 1 (Basic Ajax request creation format ):
Instance 2 (see attachment)
Consider browser compatibility Ajax request processing to obtain the background xml file
Tag: Browser server string User falseOne, using Ajax to send a GET requestSteps to send an asynchronous request-Get Ajax object: Get XMLHttpRequest Object instance-Create Request: Call the Open method of the XMLHttpRequest object-Set the callback function: Set the response function for the onreadystatechange event of the Ajax object-Send request: Call the Send me
Basic knowledge of 1.ajaxAjax is a combination of jquery, PHP and other technologies to extend the comprehensive use of technology, not new content. Ajax is also written in the listchuli.php14.ajax Basics, using AJAX as a login page, using AJAX to verify that the user name is available,
should has included the callback data, something likejQuery17209314005577471107_1335958194322({"foo":"bar"})
Here are the PHP code I used to achieve this, and which degrades if JSON (without a callback) is used:
$ret [ ' foo ' ] = "Bar" ; Finish (); function Finish () { header ( "Content-type:application/json" ); if ( $_get [ ' callback ' ] { print $_get [ ' callback ' ]. "(" ; } print json_encode ( $GLOBALS [ ' ret ' ]); if ( $
ASP. net mvc supports Ajax and webform in some differences, without updatepanel, so for beginners in the initial application does not seem to be simple in webform, however, it is more flexible in actual use, but it does not increase much complexity compared with webform.
I. Helpers of ASP. NET MVC Ajax
For ASP. net mvc Ajax learning requires a focus on understand
);}@{Html.EnableClientValidation(false);}
Note the js reference sequence.
AjaxHelper
Asynchronous link button
Note: non-intrusive Ajax must be enabled: The Jquery and unobtrusiveAjax files must be imported.
View: @ Ajax. ActionLink creates an ajax hyperlink button, which is generally used to request dynamic html code (segment View)
@
ASP. net mvc supports Ajax and webform in some differences, without updatepanel, so for beginners in the initial application does not seem to be simple in webform, however, it is more flexible in actual use, but it does not increase much complexity compared with webform.I. Helpers of ASP. NET MVC AjaxFor ASP. net mvc Ajax learning requires a focus on understanding Ajax
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.